<?php
/**
 * Created by JetBrains PhpStorm.
 * File: uploads.php
 * User: Xnfy520@gmail.com
 * Date: 12-5-6
 * Time: 下午3:27
 */
require_once 'JSON.php';
include './emit_upload.class.php';

$url =  dirname($_SERVER['PHP_SELF']);
$url = explode('/', $url);
foreach($url as $key=>$value){
	if(empty($value)){
		unset($url[$key]);
	}
};
$url = array_values($url);
$url = '/'.$url[0].'/';

$upload = new upload(array("filepath"=>"../../../Content/tmp/","allowtype"=>array('gif','png','jpg'),"israndname"=>true,"maxsize"=>3000000));
if($upload->uploadfiles('imgFile')){
	$file = $upload->getnewname();
	$file_url.=$url."Public/Content/tmp/".$file;
	header('Content-type: text/html; charset=UTF-8');
	$json = new Services_JSON();
	echo $json->encode(array('error' => 0, 'url' => $file_url));
	exit;
}else{
	alert($upload->geterrormsg());
}

function alert($msg) {
	header('Content-type: text/html; charset=UTF-8');
	$json = new Services_JSON();
	echo $json->encode(array('error' => 1, 'message' => $msg));
	exit;
}